<template>
  <div class="app-container1 show-back-class">
    <div style="width: 100%;height: 60px;border-bottom: #1C97FF 1px solid;padding:  10px 20px;display: flex;">
      <img style="width: 340px; height: 40px; margin-right: 20px;" src="@/assets/bigScreen/index/LOGO.jpg" alt="">
      <big-tab-Bar />
    </div>
    <div class="content-bottom">
     <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="70px">
       <el-form-item label="查询年份" prop="iyear">
         <el-date-picker clearable size="small" style="width: 200px;" v-model="queryParams.iyear"
                         type="year" value-format="yyyy" placeholder="选择查询年份" popper-class="show-back-class date-select-class">
         </el-date-picker>
       </el-form-item>
       <el-form-item label="项目名称" prop="projectName">
         <el-input
           v-model="queryParams.projectName"
           placeholder="请输入项目名称"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
<!--       <el-form-item label="项目" prop="projectId" >-->
<!--         <el-select v-model="queryParams.projectId" placeholder="请选择类型" style="width: 100%"  >-->
<!--           <el-option class="index-option" v-for="dict in  stationInfoList" :key="dict.stationId" v-if="dict.status===1"-->
<!--                      :label="dict.stationName" :value="parseInt(dict.stationId)" />-->
<!--         </el-select>-->
<!--       </el-form-item>-->
       <el-form-item label="方法学编号" prop="methodologyNumber" label-width="120">
         <el-input
           v-model="queryParams.methodologyNumber"
           placeholder="请输入方法学编号"
           clearable
           size="small"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>

       <el-form-item label="当前状态" prop="currentState">
         <el-select v-model="queryParams.currentState" placeholder="当前状态" clearable size="small">
           <el-option class="index-option" v-for="dict in  $store.state.ccerDict.currentStateOptions" :key="dict.dictValue"
                      :label="dict.dictLabel" :value="parseInt(dict.dictValue)" />
         </el-select>
       </el-form-item>

       <el-form-item>
         <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
       </el-form-item>
     </el-form>

     <el-row :gutter="10" class="mb8">
       <el-col :span="1.5">
         <el-button
           type="primary"
           icon="el-icon-plus"
           size="mini"
           @click="handleAdd"
           v-hasPermi="['ccer:list:addCCER']"
         >新增</el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
           type="success"
           icon="el-icon-edit"
           size="mini"
           :disabled="single"
           @click="handleUpdate"
           v-hasPermi="['ccer:list:editCCER']"
         >修改</el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
           type="danger"
           icon="el-icon-delete"
           size="mini"
           :disabled="multiple"
           @click="handleDelete"
           v-hasPermi="['ccer:list:remove']"
         >删除</el-button>
       </el-col>
	   <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
     </el-row>

     <el-table v-loading="loading" :height="tableHeight" :data="listList" @selection-change="handleSelectionChange">
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="年份" align="center" prop="iyear" width="120"/>
       <el-table-column label="项目名称" align="center" prop="projectName" />
<!--       <el-table-column label="所属项目" align="center" prop="projectId">-->
<!--         <template slot-scope="scope">-->
<!--           {{selectDictLabelAndDefault(stationInfoList,scope.row.projectId,'stationId','stationName')}}-->
<!--         </template>-->
<!--       </el-table-column>-->
       <el-table-column label="方法学编号" align="center" prop="methodologyNumber" />
       <el-table-column label="当前状态" align="center" prop="currentState" width="180" >
         <template slot-scope="scope">
           {{selectDictLabelAndDefault($store.state.ccerDict.currentStateOptions, scope.row.currentState)}}
         </template>
       </el-table-column>

       <el-table-column label="项目计入期" align="center" prop="projectDate" width="200" >
         <template slot-scope="scope">
           {{selectDictLabelAndDefault($store.state.ccerDict.projectDate, scope.row.projectDate)}}
         </template>
       </el-table-column>
       <el-table-column label="备案减排量(t)" align="center" prop="recordedEmission" />
       <el-table-column label="累计出售量(t)" align="center" prop="cumulativeSales" />
       <el-table-column label="累计剩余量(t)" align="center" prop="cumulativeSurplus" />
       <el-table-column label="累计收益(元)" align="center" prop="cumulativeReturns" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
             size="mini"
             type="text"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
             v-hasPermi="['ccer:list:editCCER']"
           >修改</el-button>
           <el-button
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             v-hasPermi="['ccer:list:remove']"
           >删除</el-button>
         </template>
       </el-table-column>
     </el-table>

     <pagination
       v-show="total>0"
       :total="total"
       :page.sync="queryParams.pageNum"
       :limit.sync="queryParams.pageSize"
       @pagination="getList"
     />

     <!-- 添加或修改CCER项目对话框 -->
     <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="120px">
         <el-form-item label="统计年份" prop="iyear">
           <el-date-picker  style="width: 100%" v-model="form.iyear"
                            type="year" value-format="yyyy" placeholder="选择查询年份">
           </el-date-picker>
         </el-form-item>
         <el-form-item label="项目名称" prop="projectName">
           <el-input v-model="form.projectName" placeholder="请输入项目名称" />
         </el-form-item>
<!--         <el-form-item label="所属项目" prop="projectId" >-->
<!--           <el-select v-model="form.projectId" placeholder="请选择类型" style="width: 100%"  >-->
<!--             <el-option v-for="dict in  stationInfoList" :key="dict.stationId" v-if="dict.status===1"-->
<!--                        :label="dict.stationName" :value="parseInt(dict.stationId)" />-->
<!--           </el-select>-->
<!--         </el-form-item>-->
         <el-form-item label="方法学编号" prop="methodologyNumber">
           <el-input v-model="form.methodologyNumber" placeholder="请输入方法学编号" />
         </el-form-item>

         <el-form-item label="当前状态" prop="currentState">
           <el-select v-model="form.currentState" placeholder="请选择当前状态" clearable size="small">
             <el-option v-for="dict in  $store.state.ccerDict.currentStateOptions" :key="dict.dictValue"
                        :label="dict.dictLabel" :value="parseInt(dict.dictValue)" />
           </el-select>
         </el-form-item>

         <el-form-item label="项目计入期" prop="projectDate">
           <el-select v-model="form.projectDate" placeholder="请选择项目计入期" clearable size="small">
             <el-option v-for="dict in  $store.state.ccerDict.projectDate" :key="dict.dictValue"
                        :label="dict.dictLabel" :value="parseInt(dict.dictValue)" />
           </el-select>
         </el-form-item>

         <el-form-item label="备案减排量" prop="recordedEmission">
           <el-input v-model="form.recordedEmission" placeholder="请输入备案减排量(t)" />
         </el-form-item>
         <el-form-item label="累计出售量" prop="cumulativeSales">
           <el-input v-model="form.cumulativeSales" placeholder="请输入累计出售量(t)" />
         </el-form-item>
         <el-form-item label="累计剩余量" prop="cumulativeSurplus">
           <el-input v-model="form.cumulativeSurplus" placeholder="请输入累计剩余量(t)" />
         </el-form-item>
         <el-form-item label="累计收益" prop="cumulativeReturns">
           <el-input v-model="form.cumulativeReturns" placeholder="请输入累计收益(元)" />
         </el-form-item>
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm">确 定</el-button>
         <el-button @click="cancel">取 消</el-button>
       </div>
     </el-dialog>
    </div>
  </div>
</template>

<script>
import { listList, getList, delList, addList, updateList, exportList } from "@/api/carbon/ccerProject";
import { stationInfoDict} from "@/api/station/stationInfo";
import bigTabBar from '@/views/components/bigTabBar/index'
export default {
  name: "List",
  components:{
    bigTabBar
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      stationInfoList:[],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // CCER项目表格数据
      listList: [],
     // // 项目名称数据
     //  nameList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        projectId: null,
        methodologyNumber: null,
        currentState: null,
        projectDate: null,
        recordedEmission: null,
        cumulativeSales: null,
        cumulativeSurplus: null,
        cumulativeReturns: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      tableHeight: '',
    };
  },
  created() {
    this.tableHeight = window.innerHeight - 350;
    stationInfoDict().then(res=>{
      if(res.data){
        this.stationInfoList=res.data
      }
    });
    this.getList();
    //this.getNameList();
  },
  methods: {
    /** 查询CCER项目列表 */
    getList() {
      this.loading = true;
      listList(this.queryParams).then(response => {
        this.listList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //
    // getNameList() {
    //   this.loading = true;
    //   this.getNameList(this.queryParams).then(response => {
    //     this.getNameList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },


    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectName: null,
        projectId: null,
        methodologyNumber: null,
        currentState: null,
        projectDate: null,
        recordedEmission: null,
        cumulativeSales: null,
        cumulativeSurplus: null,
        cumulativeReturns: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加CCER项目";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getList(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改CCER项目";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateList(this.form).then(response => {
              if (response.code === '200') {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addList(this.form).then(response => {
              if (response.code === '200') {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除CCER项目编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delList(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有CCER项目数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportList(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
<style lang="scss" scoped>
.app-container1{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #000D17;
  // background: url("../../assets/bg2.jpg") no-repeat;
  // background-size: 100% 100%;
}
.content-bottom{
  width: 100%;
  padding: 20px;
  height: calc(100% - 60px);
  background-color: #000D17;
}
.pagination-container {
  height: 50px;
}
</style>
<style>
.date-select-class {
  background-color: rgba(17,93,131,255) !important;
}
</style>
